package com.mabang.medata.client;

import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.XMLType;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class WebserviceClient {
	private String url = "";

	public WebserviceClient(String url) {
		this.url = url;
	}

	/**
	 * 
	 * @param methodName
	 *            方法名
	 * @param paramList
	 *            参数列表
	 * @return
	 */
	public String invoke(String methodName, List<Param> paramList) throws Exception
	{
		String result = "";
		Service service = new Service();
		Call call = (Call) service.createCall();
		call.setTargetEndpointAddress(url);// 远程调用路径
		call.setOperationName(new QName("http://service.medata.mabang.com/",methodName));// 调用的方法名
		// 设置返回值类型：
		call.setReturnType(XMLType.XSD_STRING);
		Object[] valueArr = new Object[paramList.size()];
		for (int i = 0; i < paramList.size(); i++) 
		{
			Param param = paramList.get(i);
			String paramName = param.getParamName();
			String paramValue = param.getParamValue();
			QName paramType = param.getParamType();
			call.addParameter(paramName,paramType,ParameterMode.IN);
			valueArr[i] = paramValue;
		}
		// 远程调用
		result = (String) call.invoke(valueArr);
		return result;
	}
}
